<HTML><HEAD>
<!--
    ----------------
    Monthly Calendar
    ----------------
-->

<SCRIPT LANGUAGE="JavaScript"><!-- hide from old browsers

/*
    THE JAVASCRIPT COOKBOOK by Erica Sadun, webrx@mindspring.com
							& J. Brook Monroe, mrprogguy@techie.com
    Copyright (C)1997 by Charles River Media.  All Rights Reserved.
    
    This applet can only be re-used or modifed by license holders of the
    JavaScript Cookbook CD-ROM.  Credit must be given in the source
    code and this copyright notice must be maintained. If you do
    not hold a license to the JavaScript Cookbook, you may NOT
    duplicate or modify this code for your own use.

    Use at your own risk. No warranty is given or implied of the suitability 
    of this applet for any specific application. Neither Erica Sadun nor 
    Charles River Media will be held responsible for any unwanted effects 
    due to the use of this applet or any derivative. 
*/

var MonthName = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var MonthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

function DayString(dt,today)
{
	var outstr = '<TD COLSPAN=1 VALIGN="TOP" ALIGN="RIGHT" ';
	if(dt == today)
		outstr += 'BGCOLOR="#40FF10"';
	outstr += '>'+dt+'</TD>';
	return outstr;
}

function GenerateCalendar()
{
	var dCurrent	= new Date();
	var m 			= dCurrent.getMonth();
	var today 		= dCurrent.getDate();
	var dt 			= 1;
	var l			= MonthLength[m];
	var col			= 0;
	var i;
	var day;

	if(m == 1) {
		y = dCurrent.getYear();	// February gets an extra day in a leap year;
		if((y % 4) == 0)		// a leap year is any year evenly divisible
			if((y % 100) != 0)	// by four, but not evenly divisible by 100.
				l++;			// 1996 was a leap year but 2000 isn't.	
	}

	document.writeln('<CENTER><FONT FACE="Arial,Helvetica" SIZE="5">'+MonthName[m]+'</FONT></CENTER>');
	
	var d1st = new Date(dCurrent.getYear(),m,1);
	day = d1st.getDay();
	
	document.writeln('<CENTER><TABLE CELLPADDING=1 CELLSPACING=2 BORDER=1><TR><TH COLSPAN=1>SUN</TH><TH COLSPAN=1>MON</TH><TH COLSPAN=1>TUE</TH><TH COLSPAN=1>WED</TH><TH COLSPAN=1>THU</TH><TH COLSPAN=1>FRI</TH><TH COLSPAN=1>SAT</TH></TR>');
	//
	// Write out first week
	//
	document.write('<TR>');
	for(i = 0; i < day; i++)
		document.write('<TD COLSPAN=1> </TD>');
	for(i = day; i < 7; i++) {
		document.write(DayString(dt,today));
		dt++;
	}
	document.writeln('</TR>');
	document.write('<TR>');
	//
	// Write out remainder of month
	//
	while(dt <= l) {
	    document.write(DayString(dt,today));
		col++;
		if((col % 7) == 0) {
			document.writeln('</TR>');
			if(dt < (l - 1))
				document.write('<TR>');
		}
		dt++;
		
	}
	document.write('</TABLE></CENTER>');
}
//-->
</SCRIPT>

<BODY bgcolor="ffffff" link="0000ff" vlink="770077">
    
    <FONT COLOR="007777"><H1><IMG SRC="../GRAFX/UTENS.JPG" WIDTH=80 HEIGHT=50
    ALIGN = LEFT>Monthly Calendar</H1></FONT>
    <BLOCKQUOTE><FONT COLOR="770000">
        This script creates a calendar for the current month,
        highlighting the current day.<p>
    </FONT></BLOCKQUOTE>
    
	<SCRIPT LANGUAGE="JavaScript">
	GenerateCalendar();
	</SCRIPT>
    <FONT COLOR="007777"><H2>Discussion</H2></FONT>
    <FONT SIZE=4>
        This script uses the the <FONT color=770000">Date</FONT> object to determine
		the current date, and creates a table presenting the
		calendar for the current month.  The algorithm for generating the calendar is
		probably more interesting than the <FONT color=770000">Date</FONT> object itself,
		as it involves determining whether or not the current year is a leap year, and
		padding the calendar properly to account for the weekday on which the first day
		of the month occurs.
    </FONT>        
<BR><BR><h5>Copyright ©2000 by Charles River Media, All Rights Reserved</h5>
</BODY>
</HTML>